package com.ysh.spring;

import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 袁胜虎 on 2022/9/1 16:15
 */
@Component
@EnableScheduling//开启任务调度
public class MyJob {
    //fixedDelay循环的间隔,单位毫秒,要等任务结束之后才继续
//     @Scheduled(fixedDelay = 5000)
    public void naozhong(){
        try {
            Thread.sleep(6000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.err.println("MyJob中的方法naozhong执行了!!!");
    }
    @Scheduled(fixedDelay = 5000)
    public void test2(){
        try {
            Thread.sleep(6000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.err.println("MyJob中的方法test2执行了!!!");
    }

//    @Scheduled(cron = "0/2 * * * * ?")
    public void test3(){
      System.err.println("MyJob中的方法test3执行了!!!");
    }
}
